package com.healer.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
//@Profile("dev")
@Configuration
@EnableSwagger2 //开启swagger2
public class SwaggerConfig {
    @Bean
    public Docket docket1(){
        Docket docket = new Docket(DocumentationType.SWAGGER_2).groupName("part1");
        return docket;
    }
    @Bean
    public Docket docket2(){
        Docket docket = new Docket(DocumentationType.SWAGGER_2).groupName("part2");
        return docket;
    }
    @Bean
    public Docket docket3(){
        Docket docket = new Docket(DocumentationType.SWAGGER_2).groupName("part3");
        return docket;
    }

    /**
     * 功能描述：配置了swagger2的docket的bean实例
     * @return
     */
    @Bean
    public Docket docket(Environment environment){
        //设置要显示的环境
        Profiles dev = Profiles.of("dev");
//        通过是否处在自己设定的环境中
        boolean b = environment.acceptsProfiles(dev);
        System.out.println("是不是dev"+b);
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("master")
                .enable(b)//默认为true,用来决定swagger是否启用
                .select()
                //RequestHandlerSelectors,配置要扫描接口的方式
                //basePackage：指定要扫描的包
                //any():扫描全部
                //none():不扫描
                //withClassAnnotation:扫描类上的注解，参数是一个注解的反射对象
                //withMethodAnnotation:扫描方法上的注解
                .apis(RequestHandlerSelectors.basePackage("com.healer.controller"))
                //paths()，过滤什么路径
//                .paths(PathSelectors.ant(""))
                .build();
    }

    /**
     * 功能描述：配置swagger的apiInfo
     * @return
     */
    public ApiInfo apiInfo(){
//        作者信息
        Contact 陈鹏 = new Contact("陈鹏", "https://gitee.com/healer512", "mingx862@gmail.com");
        return new ApiInfo(
                "陈鹏的swagger学习",
                "专为学习而来",
                "1.1.1.1.1",
                "http://localhost/swagger2/swagger-ui.html",
                陈鹏,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }
}
